package com.igeek.clud_system.service;

import com.igeek.clud_system.dao.ClubDao;
import com.igeek.clud_system.dao.ClubMemberDao;
import com.igeek.clud_system.dao.InformationDao;
import com.igeek.clud_system.dao.StudentDao;
import com.igeek.clud_system.entity.Club;
import com.igeek.clud_system.entity.ClubMembers;
import com.igeek.clud_system.entity.LntegrityScoreValue;
import com.igeek.clud_system.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class StudentService {
    @Autowired
    StudentDao studentDao;

    @Autowired
    ClubDao clubDao;

    @Autowired
    InformationDao informationDao;
    @Autowired
    ClubMemberDao clubMemberDao;

    public Student findStudentById(Integer id){
        return studentDao.findStudentById(id);
        //return null;
    }
    public void updateStudentHead(String head,Integer id){
        studentDao.updateStudentHead(head,id);
    }
    public void updateStudentPassword(String password,Integer id){
        studentDao.updateStudentPassword(password,id);
    }

    /**
     * 对社团身份进行变更
     */
    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.READ_COMMITTED)
    public void updateMan(Integer role,Integer clubId,Integer studentId){
        studentDao.updateMan(role,clubId,studentId);
//        发送消息
        String value = null;
        Club clubById = clubDao.findClubById(clubId);
        if(role == 2){
            value="你已被"+clubById.getClubName()+"设为管理员";
        }else {
            value="你已被"+clubById.getClubName()+"取消管理员权限";
        }
        System.out.println(1);
        informationDao.insertInfor(studentId,value,new Date(),1);

    }

    /**
     * 对社团成员删除
     */
    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.READ_COMMITTED)
    public void deleteClubMan(Integer clubId,Integer studentId){
        studentDao.deleteMan(clubId,studentId);
        String value = null;
        Club clubById = clubDao.findClubById(clubId);
        value = "你已被"+clubById.getClubName()+"移出社团";
        informationDao.insertInfor(studentId,value,new Date(),1);
    }
    //查身份
    public ClubMembers findRole(Integer clubId,Integer studentId){
        clubMemberDao.findRole(clubId,studentId);
        return clubMemberDao.findRole(clubId,studentId);
    }
}




